import axios from 'axios';
import baseConfig from '@/config';
import { getQueryParam } from './index';

const http = axios.create({
	baseURL: baseConfig.BASE_URL, // baseURL
	headers: {
		Authorization: getQueryParam('token') || baseConfig.LL_APP_TOKEN
	},
	withCredentials: false // 跨域请求时是否需要使用凭证
});

// request 拦截器
http.interceptors.request.use(
	(config) => {
		return config;
	},
	(error) => {
		return Promise.reject(error);
	}
);

// response 拦截器
http.interceptors.response.use(
	(response) => {
		// 响应成功
		return Promise.resolve(response.data);
	},
	(error) => {
		// 响应失败
		return Promise.reject(error);
	}
);

export default http;
